<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改大屏信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-procurer-edit" th:object="${userVisualBase}" >
        <input th:field="*{picUrl}" class="form-control" readonly="readonly" type="hidden"/>
        <input id="id" name="id" class="form-control" type="hidden" th:field="*{id}" required>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">大屏名称：</label>
            <div class="col-sm-8">
                <input id="visualName" name="visualName" class="form-control" type="text" th:field="*{visualName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">发布状态：</label>
            <div class="col-sm-8">
                <select name="status" required class="form-control" th:field="*{onlineStatus}"  th:with="type=${@dict.getType('online_status')}">
                    <option value="">--请选择发布状态--</option>
                    <option th:selected="${onlineStatus eq dict.dictValue}"
                            th:each="dict : ${type}"
                            th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
                <label class="col-sm-3 control-label is-required">附件上传：</label>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input
                                id="file"
                                name="file"
                                data-show-preview="true"
                                type="file"
                                multiple
                                data-max-file-count="1"
                                data-theme="fas">
<!--                        <input id="file" type="file" multiple>-->
                    </div>
                </div>
        </div>

        <div class="form-group">
            <div class="col-sm-3">
                <div th:object="${user}">
                    <input th:field="*{userId}" class="form-control" readonly="readonly" type="hidden" name="updateUser"/>
                    <input th:field="*{loginName}" class="form-control" readonly="readonly" type="hidden" name="updateUser"/>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix = ctx + "system/UserVisualBase";
    $(document).ready(function () {
        $("#file").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': '#',
            initialPreviewAsData: true,
            autoReplace:true,
            showRemove:false,
            showUpload:false,
            layoutTemplates :{
                actionDelete:'', //去除上传预览的缩略图中的删除图标
                actionUpload:'',//去除上传预览缩略图中的上传图片；
                actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
            },
            initialPreview: [
                ctx + $("#picUrl").val()
            ]
        });
    });

    $("#form-procurer-edit").validate({
        onkeyup: false,
        onSubmit: true,
        rules: {
            visualName: {
                required: true,
                remote: {
                    url: prefix + "/checkVisualBaseNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "id":function () {
                            return $.common.trim($("#id").val());
                        },
                        "visualName": function () {
                            return $.common.trim($("#visualName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return data;
                    }
                }
            }
        },
        messages: {
            "visualName": {
                remote: "大屏名不能重复"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        var formData = new FormData($('#form-procurer-edit')[0]);
        formData.append('file', $('#file')[0].files[0]);


        if ($.validate.form()) {
            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }
</script>
</body>
</html>
